% TEST_ID: LANG-EXPAND-0064
% CATEGORY: language/convert
% 测试 cell2struct

function test_cell2struct
    devel = {{'Lee', 'Reed', 'Hill'}, {'Dean', 'Frye'}, {'Lane', 'Fox', 'King'}};
    sales = {{'Howe', 'Burns'}, {'Kirby', 'Ford'}, {'Hall'}};
    mgmt = {{'Price'}, {'Clark', 'Shea'}, {'Sims'}};
    qual = {{'Bates', 'Gray'}, {'Nash'}, {'Kay', 'Chase'}};
    docu = {{'Lloyd', 'Young'}, {'Ryan', 'Hart', 'Roy'}, {'Marsh'}};

    employees = [devel; sales; mgmt; qual; docu]

    rowHeadings = {'development', 'sales', 'management', 'quality', 'documentation'};

    depts = cell2struct(employees, rowHeadings, 1)
    S = struct();
    S.development = {'Dean' 'Frye'};
    S.sales = {'Kirby' 'Ford'};
    S.management = {'Clark' 'Shea'};
    S.quality = {'Nash'};
    S.documentation = {'Ryan' 'Hart' 'Roy'};
    assert_istrue(S, depts(2));

    function assert_istrue(s1, s2)
        assert_istrueCell(s1.development, s2.development);
        assert_istrueCell(s1.sales, s2.sales);
        assert_istrueCell(s1.management, s2.management);
        assert_istrueCell(s1.quality, s2.quality);
        assert_istrueCell(s1.documentation, s2.documentation);
    end


    rowHeadings = {'development', 'sales', 'management'};
    depts = cell2struct(repmat(employees, 1, 1, 2), rowHeadings, 2)

    S = struct();
    S.development = {'Bates' 'Gray'};
    S.sales = {'Nash'};
    S.management = {'Kay' 'Chase'};
    assert_istrue2(S, depts(4));


    S.development = {'Howe' 'Burns'}
    S.sales = {'Kirby' 'Ford'}
    S.management = {'Hall'}
    assert_istrue2(S, depts(7))

    function assert_istrue2(s1, s2)
        assert_istrueCell(s1.development, s2.development);
        assert_istrueCell(s1.sales, s2.sales);
        assert_istrueCell(s1.management, s2.management);
    end

end



function assert_istrueCell(x, y)
    for i = 1:numel(y)
        assert(x{i} == y{i})
    end
end